<!-- 免考申请 -->
<template>
  <div class="ApplyFor">
    <div class="ApplyForButton">
      <el-button
        type="primary"
        class="ApplyForButton-on"
        @click="dialogFormVisible = true"
        >申请</el-button
      >
      <el-dialog
        title="学年: 2019-2020 学期: 2"
        :visible.sync="dialogFormVisible"
        :modal="false"
      >
        <el-form :model="addform">
          <el-form-item label="*姓名" :label-width="formLabelWidth">
            <el-input
              v-model="addform.name"
              autocomplete="off"
              style="width:30%"
            ></el-input>
          </el-form-item>
          <el-form-item label="*学号" :label-width="formLabelWidth">
            <el-input
              v-model="addform.data"
              autocomplete="off"
              style="width:40%"
            ></el-input>
          </el-form-item>
          <el-form-item label="*课程:" :label-width="formLabelWidth">
            <el-select v-model="addform.course" placeholder="-请选择-">
              <el-option label="大学语文" value="大学语文"></el-option>
              <el-option label="高等数学" value="高等数学"></el-option>
              <el-option label="大学英语" value="大学英语"></el-option>
              <el-option label="大学体育" value="大学体育"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="*说明:" :label-width="formLabelWidth">
            <el-input
              v-model="addform.explain"
              autocomplete="off"
              type="textarea"
              style="width: 70%;"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="
              dialogFormVisible = false;
              handleaddtable();
            "
            >提 交</el-button
          >
        </div>
      </el-dialog>
    </div>

    <div class="ApplyForForm">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="序号" width="160" align="center">
        </el-table-column>
        <el-table-column prop="data" label="学号" width="160" align="center">
        </el-table-column>
        <el-table-column prop="name" label="姓名" width="160" align="center">
        </el-table-column>
        <el-table-column
          prop="schoolsemester"
          label="学年 | 学期"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="course" label="课程" width="160" align="center">
        </el-table-column>
        <el-table-column prop="explain" label="说明" width="210" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="
                handleEdit(scope.$index, scope.row);
                dialogFormVisibles = true;
              "
              >编辑</el-button
            >
            <el-dialog
              title="免修申请表"
              :visible.sync="dialogFormVisibles"
              :modal="false"
              align="left"
            >
              <el-form :model="form">
                <el-form-item label="姓名" :label-width="formLabelWidth">
                  <el-input
                    v-model="form.name"
                    autocomplete="off"
                    style="width:30%"
                  ></el-input>
                </el-form-item>
                <el-form-item label="学号" :label-width="formLabelWidth">
                  <el-input
                    v-model="form.data"
                    autocomplete="off"
                    style="width:40%"
                  ></el-input>
                </el-form-item>
                <el-form-item label="课程" :label-width="formLabelWidth">
                  <el-select v-model="form.course" placeholder="请选择课程">
                    <el-option label="大学语文" value="大学语文"></el-option>
                    <el-option label="大学英语" value="大学英语"></el-option>
                    <el-option label="大学体育" value="大学体育"></el-option>
                    <el-option label="高等数学" value="高等数学"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="*说明:" :label-width="formLabelWidth">
                  <el-input
                    v-model="form.explain"
                    autocomplete="off"
                    type="textarea"
                    style="width: 70%;"
                  ></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibles = false">取 消</el-button>
                <el-button
                  type="primary"
                  @click="
                    dialogFormVisibles = false;
                    handleamend(scope.$index, scope.row);
                  "
                  >确 定</el-button
                >
              </div>
            </el-dialog>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    return {
      //表格的数据
      tableData: [
        {
          id: 1,
          data: "1307410042",
          name: "王小虎",
          schoolsemester: "2019-2020学年 | 2",
          course: "大学体育",
          explain: "1、因个人心脏原因申请免修该课程 2、证明材料详情见附件",
          operation: "编辑 | 状态",
        },
        {
          id: 1,
          data: "1307410042",
          name: "王小虎",
          schoolsemester: "2019-2020学年 | 2",
          course: "大学体育",
          explain: "1、因个人心脏原因申请免修该课程 2、证明材料详情见附件",
          operation: "编辑 | 状态",
        },
      ],

      form: {
        name: "",
        data: "",
        course: "",
        explain: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      addform: {
        id: 1,
        name: "",
        data: "",
        explain: "",
        schoolsemester: "2019-2020学年 | 2",
        course: "",
      },
      tableId: 1,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      formWidth: "70px",
      dialogFormVisibles: false,
    };
  },

  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    handleEdit(index, row) {
      // console.log(index, row);
      // console.log(row.name);
      this.form.name = row.name;
      this.form.data = row.data;
      this.form.course = row.course;
      this.form.explain = row.explain;
    },
    handleDelete(index, row) {
      console.log(index, row);
      this.tableData.shift(index)
    },
    handleamend(index, row) {
      console.log(index, row);
      // console.log(row.name);
      console.log(this.tableData[0].name);
      this.tableData[0].name = this.form.name;
      this.tableData[0].data = this.form.data;
      this.tableData[0].course = this.form.course;
      this.tableData[0].explain = this.form.explain;
    },
    handleaddtable() {
      let newTable = {};
      newTable = this.addform;
      console.log(newTable);
      this.tableData.push(newTable);

    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
.ApplyFor {
  overflow: hidden;
  .ApplyForButton {
    overflow: hidden;
    display: flex;
    margin: 10px 0;
    position: relative;
    left: 1080px;
  }
  .ApplyForForm {
  }
}
</style>
